home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 3 / Gekikoh Dennoh Club Vol. 3 (Japan) (Track 1).bin / docs / panda / playw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-19  |  7.0 KB  |  396 lines

  1. /*
  2.     qv2 play wait
  3. */
  4.  
  5. #include    <stdio.h>
  6. #include    <stdlib.h>
  7. #include    <io.h>
  8. #include    <graph.h>
  9. #include    <doslib.h>
  10. #include    <iocslib.h>
  11.  
  12. char    Y_TBL[65536];
  13.  
  14.  
  15. unsigned short *gbuf;
  16.  
  17.  
  18. int    main(argc,argv)
  19. int    argc;
  20. char    *argv[];
  21. {
  22.     FILE    *fp;
  23.     int    fn,tfn;
  24.     short    *addr;
  25. //    int    sx=48,sy=84;        //補正しない
  26.     int    sx=48,sy=38;        //補正する
  27.     int    len;
  28.     int    ed;
  29.     int    ssp;
  30.     int    mode=0;
  31.     int    st,wt;
  32.     
  33.     if( argc!=3 ){
  34.         printf("usage : @>playw file wait\n");
  35.         goto quick_exit;
  36.     }
  37.     wt=atoi(argv[2]);
  38.     screen(1,3,1,1);
  39.     if( argc!=1 ){
  40.         CRTMOD(270);
  41.     }
  42.     printf("計算中…\n");
  43.     mktbl();
  44.     printf("データ読み込み中…\n");
  45.     fp=fopen(argv[1],"rb");
  46.     len=filelength(fileno(fp));
  47.     gbuf=MALLOC(len);
  48.     if( (int)gbuf<0 ){
  49.         printf("メモリ不足\n");
  50.         fclose(fp);
  51.         goto quick_exit;
  52.     }
  53.     fread(gbuf,2,len/2,fp);
  54.     fclose(fp);
  55.     cls();
  56.     
  57.     ssp=B_SUPER(0);
  58.     cls();
  59.     ed=len/38400;
  60.     while(1){
  61.         for( fn=1;fn<=ed;fn++ ){
  62.             st=ONTIME();
  63.             printf("\x0d%03d ",fn);
  64. //            put(sx,sy,sx+159,sy+119,gbuf+19200*(fn-1),38400);    //160*120
  65.  
  66. /*
  67.             putQV2wf(sx,sy,gbuf+19200*(fn-1));    //160*120
  68. */
  69.  
  70.             switch( BITSNS(0x00) ){
  71.                 case 0x00:    //
  72.                     putQV2wn(sx,sy,gbuf+19200*(fn-1));    //160*120
  73.                     printf("no");
  74.                 break;
  75.                 case 0x04:    //1
  76.                     putQV2wf(sx,sy,gbuf+19200*(fn-1));    //160*120
  77.                     printf("fi");
  78.                 break;
  79.                 case 0x08:    //2
  80.                     putQV2wc(sx,sy,gbuf+19200*(fn-1));    //160*120
  81.                     printf("c0");
  82.                 break;
  83.                 case 0x10:    //3
  84.                     putQV2wcc(sx,sy,gbuf+19200*(fn-1));    //160*120
  85.                     printf("cc");
  86.                 break;
  87.                 case 0x20:    //4
  88.                     if( fn&1 ){
  89.                         putQV2wn(sx,sy,gbuf+19200*(fn-1));    //160*120
  90.                     }
  91.                     else{
  92.                         putQV2wf(sx,sy,gbuf+19200*(fn-1));    //160*120
  93.                     }
  94.                     printf("nf");
  95.                 break;
  96.             }
  97.  
  98.             while( st+wt>ONTIME() ){
  99.                 if( BITSNS(0x00)==0x02 ){
  100.                     goto quick_exit;
  101.                 }
  102.             }
  103.         }
  104.     }
  105.     B_SUPER(ssp);
  106.  
  107. quick_exit:;
  108.     KFLUSHIO(0xff);
  109.     
  110. }
  111.  
  112.  
  113.  
  114.  
  115. int    mktbl()
  116. {
  117.     int col;
  118.     int    r,g,b,gray;
  119.     
  120.     for( col=0;col<=0xffff;col++ ){
  121.         r=(col&0b0000011111000000)>>6;
  122.         g=(col&0b1111100000000000)>>11;
  123.         b=(col&0b0000000000111110)>>1;
  124. //        0.299 0.587 0.114
  125.         r*=1000;
  126.         g*=1000;
  127.         b*=1000;
  128.         gray=r*0.299+g*0.587+b*0.114;
  129.         gray/=1000;
  130.         Y_TBL[col]=(char)gray;
  131.     }
  132.  
  133. }
  134.  
  135.  
  136.  
  137.  
  138. //単純補間
  139. int    putQV2wn(px,py,addr)
  140. int    px,py;
  141. unsigned short    *addr;
  142. {
  143.     int    x,y;
  144.     unsigned short *s,*d;
  145.     
  146.     s=addr;
  147.     d=(unsigned short *)0xc00000+py*512+px;
  148.     for( y=0;y<120;y+=2 ){
  149.         //偶数ラインは2重描画
  150.         for( x=0;x<20;x++ ){
  151.             *d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;
  152.         }
  153.         d+=352;        //512-160
  154.         s-=160;
  155.         for( x=0;x<20;x++ ){
  156.             *d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;
  157.         }
  158.         d+=352;        //512-160
  159.  
  160.         for( x=0;x<20;x++ ){
  161.             *d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;
  162.         }
  163.         d+=352;        //512-160
  164.     }
  165. }
  166.  
  167.  
  168.  
  169.  
  170. //櫛形補間
  171. int    putQV2wf(px,py,addr)
  172. int    px,py;
  173. unsigned short    *addr;
  174. {
  175.     int    x,y;
  176.     unsigned short *s,*d;
  177.     
  178.     s=addr;
  179.     d=(unsigned short *)0xc00000+py*512+px;
  180.     for( y=0;y<120;y+=2 ){
  181.  
  182. /*
  183.     uuuu
  184.     udud
  185.     dddd
  186. */
  187.         //u
  188.         for( x=0;x<20;x++ ){
  189.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  190.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  191.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  192.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  193.         }
  194. //        d+=352;        //(512-160)+512
  195.         d+=864;        //(512-160)+512
  196.  
  197.         //d
  198.         for( x=0;x<20;x++ ){
  199.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  200.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  201.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  202.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  203.         }
  204.         d+=352;        //512-160
  205.  
  206.     }
  207. }
  208.  
  209.  
  210.  
  211. //色差計算
  212. int    putQV2wc(px,py,addr)
  213. int    px,py;
  214. unsigned short    *addr;
  215. {
  216.     int    x,y;
  217.     unsigned short *su,*sd,*du,*dm,*dd;
  218.     unsigned short    uc,mc,dc,    ur,ug,ub,    dr,dg,db,    mr,mg,mb;
  219.  
  220.     su=addr;
  221.     sd=addr+160;
  222.     du=(unsigned short *)0xc00000+py*512+px;
  223.     dm=(unsigned short *)0xc00000+py*512+px+512;
  224.     dd=(unsigned short *)0xc00000+py*512+px+1024;
  225.  
  226.     for( y=0;y<120;y+=2 ){
  227.  
  228.         //u意味なしか
  229.         for( x=0;x<40;x++ ){    *du++=*su++;*du++=*su++;*du++=*su++;*du++=*su++;    }
  230.  
  231.         //d
  232.         for( x=0;x<40;x++ ){    *dd++=*sd++;*dd++=*sd++;*dd++=*sd++;*dd++=*sd++;    }
  233.  
  234.         su-=160;
  235.         sd-=160;
  236.  
  237.         for( x=0;x<160;x++ ){
  238.             //レジスタがたりんぞい
  239.             uc=*su++;
  240.             dc=*sd++;
  241.             ur=(uc&0b0000011111000000)>>6;
  242.             ug=(uc&0b1111100000000000)>>11;
  243.             ub=(uc&0b0000000000111110)>>1;
  244.             dr=(dc&0b0000011111000000)>>6;
  245.             dg=(dc&0b1111100000000000)>>11;
  246.             db=(dc&0b0000000000111110)>>1;
  247.             mr=((ur+dr)>>1)<<6;
  248.             mg=((ug+dg)>>1)<<11;
  249.             mb=((ub+db)>>1)<<1;
  250.             mc=mr;
  251.             mc|=mg;
  252.             mc|=mb;
  253.             *dm++=mc;
  254.         }
  255.  
  256.         du+=1376;        //(512-160)+1024
  257.         dm+=1376;
  258.         dd+=1376;
  259.         su+=160;
  260.         sd+=160;
  261.  
  262.     }
  263.  
  264.  
  265. }
  266.  
  267.  
  268.  
  269.  
  270. //色差検査後計算orコピー
  271. int    putQV2wcc(px,py,addr)
  272. int    px,py;
  273. unsigned short    *addr;
  274. {
  275.     int    x,y;
  276.     unsigned short *su,*sd,*du,*dm,*dd;
  277.     unsigned short    uc,mc,dc,    ur,ug,ub,    dr,dg,db,    mr,mg,mb;
  278.     
  279.     su=addr;
  280.     sd=addr+160;
  281.     du=(unsigned short *)0xc00000+py*512+px;
  282.     dm=(unsigned short *)0xc00000+py*512+px+512;
  283.     dd=(unsigned short *)0xc00000+py*512+px+1024;
  284.  
  285.     for( y=0;y<120;y+=2 ){
  286.  
  287.         //u意味なしか
  288.         for( x=0;x<40;x++ ){    *du++=*su++;*du++=*su++;*du++=*su++;*du++=*su++;    }
  289.  
  290.         //d
  291.         for( x=0;x<40;x++ ){    *dd++=*sd++;*dd++=*sd++;*dd++=*sd++;*dd++=*sd++;    }
  292.  
  293.         su-=160;
  294.         sd-=160;
  295.  
  296.         for( x=0;x<160;x++ ){
  297.             //レジスタがたりんぞい
  298.             uc=*su++;
  299.             dc=*sd++;
  300.  
  301. //            printf("%d,",(max((int)Y_TBL[uc],(int)Y_TBL[dc])-min((int)Y_TBL[uc],(int)Y_TBL[dc])));
  302.  
  303.             if( (max((int)Y_TBL[uc],(int)Y_TBL[dc])-min((int)Y_TBL[uc],(int)Y_TBL[dc]))>=12 ){
  304.                 //37.5%以上の輝度変化があった場合
  305.                 ur=(uc&0b0000011111000000)>>6;
  306.                 ug=(uc&0b1111100000000000)>>11;
  307.                 ub=(uc&0b0000000000111110)>>1;
  308.                 dr=(dc&0b0000011111000000)>>6;
  309.                 dg=(dc&0b1111100000000000)>>11;
  310.                 db=(dc&0b0000000000111110)>>1;
  311.                 mr=((ur+dr)>>1)<<6;
  312.                 mg=((ug+dg)>>1)<<11;
  313.                 mb=((ub+db)>>1)<<1;
  314.                 mc=mr;
  315.                 mc|=mg;
  316.                 mc|=mb;
  317.                 *dm++=mc;
  318.             }
  319.             else{
  320.                 //変化が少なければ上の色をそのまま
  321.                 *dm++=uc;
  322.             }
  323.  
  324.         }
  325.  
  326.         du+=1376;        //(512-160)+1024
  327.         dm+=1376;
  328.         dd+=1376;
  329.         su+=160;
  330.         sd+=160;
  331.  
  332.     }
  333.  
  334.  
  335. }
  336.  
  337.  
  338.  
  339.  
  340. //色差計算for 68060
  341. int    putQV2wc060(px,py,addr)
  342. int    px,py;
  343. unsigned short    *addr;
  344. {
  345.     int    x,y;
  346.     unsigned short *su,*sd,*du,*dm,*dd;
  347.     unsigned short    uc,mc,dc,    ur,ug,ub,    dr,dg,db,    mr,mg,mb;
  348.  
  349.     su=addr;
  350.     sd=addr+160;
  351.     du=(unsigned short *)0xc00000+py*512+px;
  352.     dm=(unsigned short *)0xc00000+py*512+px+512;
  353.     dd=(unsigned short *)0xc00000+py*512+px+1024;
  354.  
  355.     for( y=0;y<120;y+=2 ){
  356.  
  357.         for( x=0;x<160;x++ ){
  358.  
  359.             uc=*su++;
  360.             dc=*sd++;
  361.  
  362.             *du++=uc;
  363.             *dd++=dc;
  364.  
  365.             uc&=0b0000011111000000;
  366.             uc>>=6;
  367.             ur=uc;                //@@以下、
  368.             ug=(uc&0b1111100000000000)>>11;
  369.             ub=(uc&0b0000000000111110)>>1;
  370.             dr=(dc&0b0000011111000000)>>6;
  371.             dg=(dc&0b1111100000000000)>>11;
  372.             db=(dc&0b0000000000111110)>>1;
  373.             mr=((ur+dr)>>1)<<6;
  374.             mg=((ug+dg)>>1)<<11;
  375.             mb=((ub+db)>>1)<<1;
  376.             mc=mr;
  377.             mc|=mg;
  378.             mc|=mb;
  379.             *dm++=mc;
  380.         }
  381.  
  382.         du+=1376;        //(512-160)+1024
  383.         dm+=1376;
  384.         dd+=1376;
  385.         su+=160;
  386.         sd+=160;
  387.  
  388.     }
  389.  
  390.  
  391. }
  392.  
  393.  
  394.  
  395.  
  396.